<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>电影列表页面</title>
    <link rel="stylesheet" th:href="@{/static/css/user.css}" type="text/css"/>
</head>
<body>
<h3>欢迎<a th:href="@{/user/record}" th:text="${session.user.userName}"/></h3>
<h3>在线人数<span th:text="${application.onlinecount}"></span>人</h3>
<a th:href="@{/login/exit}">[退出系统]</a>


<h1 align="center">电影列表</h1>
<hr >
<table border="1px" align="center" width="50%">
    <tr>
        <th>电影编号</th>
        <th>电影名字</th>
        <th>电影评分</th>
        <th>操作</th>
    </tr>

    <tr th:each="movie : ${movies}">
        <td th:text="${movie.id}"></td>
        <td th:text="${movie.movieName}"></td>
        <td th:text="${movie.movieScore}"></td>
        <td>
            <a th:href="@{'/root/delete/' + ${movie.id}}" onclick="confirmDelete(event)">删除</a>
            <a th:href="@{'/root/modify/' + ${movie.id}}">修改</a>
            <a th:href="@{'/root/detail/' + ${movie.id}}">详情</a>
        </td>
    </tr>

</table>

<script>
    function confirmDelete(event){
        if(window.confirm("确定删除？")){
            let delForm = document.getElementById("delForm");
            delForm.action = event.target.href;
            delForm.submit();
        }
        event.preventDefault();
    }
</script>

<hr >
<a th:href="@{/root/add}">新增电影</a>

<div style="display: none">
    <form id="delForm" method="post">
        <input type="hidden" name="_method" value="delete">
    </form>
</div>

</body>
</html>
